#!/usr/bin/env python2.5
#coding: utf8

#Author: Gang Li
#Date: 2010-04-10 18:20

from core.utils import *
from core.transport import Client, CmdDispatcher, CmdFilter, HeartBeat

class Submiter(CmdFilter):

    hb = HeartBeat()
    def __init__(self, srv_ip, srv_port):
        self.client = Client(srv_ip, srv_port, self)
        self.client.add_cmd_observer(self)
        self.client.add_cmd_observer(self.hb)

    def run_task(self, task):
        self.client.write(START_TASK, task)

    def connected(self, sock):
        print "connected to server, verify ok"

    def disconnected(self, sock):
        print "connected to server, verify ok"

    def close(self):
        self.client.close()
        self.hb.close()

    def on_cmd(self, msg):
        print "recv cmd %s", msg
